//
//  AutumnDetailViewController.m
//  ProjectA
//
//  Created by dlios on 15-3-6.
//  Copyright (c) 2015年 dlios. All rights reserved.
//

#import "AutumnDetailViewController.h"

@interface AutumnDetailViewController ()

@end

@implementation AutumnDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.myScrollerV = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.myScrollerV.backgroundColor = [UIColor whiteColor];
    
    [self.view addSubview:self.myScrollerV];
    //-------------------------解析数据----------------------------------------//
    NSString *str = [NSString stringWithFormat:@"http://api.yi18.net/cook/show?id=%@",self.id];
    
    [AFNDownLoader getDataDownLoad:str block:^(id myData) {
        NSMutableDictionary *dic = myData;
        //此处是字典不是数组就只是单组数据
        NSMutableDictionary *myDic = [dic objectForKey:@"yi18"];
        //方法步骤
        //解析的数据中有符号 去掉符号
        self.methodLable = [[UILabel alloc] initWithFrame:CGRectMake(30, 120, self.view.frame.size.width - 60, self.view.frame.size.height - 80)];
        NSString *string = [myDic objectForKey:@"message"];
        NSString *string1 =  [string stringByReplacingOccurrencesOfString:@"<p>" withString:@""];
        NSString *string2 = [string1 stringByReplacingOccurrencesOfString:@"<h2>" withString:@""];
        NSString *string3 = [string2 stringByReplacingOccurrencesOfString:@"</h2>" withString:@""];
        NSString *string4 = [string3 stringByReplacingOccurrencesOfString:@"</p>" withString:@""];
        NSString *string5 = [string4 stringByReplacingOccurrencesOfString:@"<br />" withString:@""];
        NSString *string6 = [string5 stringByReplacingOccurrencesOfString:@"&nbsp" withString:@""];
        //lable赋值
        self.methodLable.text = string6;
        self.methodLable.numberOfLines = 0;
        
        //lable自适应高度
        CGRect frame = self.methodLable.frame;
        frame.size.height = [[self class] heightForContentText:string6] + self.imageV.frame.origin.y + self.imageV.frame.size.height +270;
        self.methodLable.frame = frame;
        
        self.myScrollerV.contentSize = CGSizeMake(self.view.frame.size.width, frame.size.height + 50);
        
        
        //赋值图片
        self.imageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 180)];
        NSString *pictureStr = [myDic objectForKey:@"img"];
        NSString *urlStr = [NSString stringWithFormat:@"http://www.yi18.net/%@",pictureStr];
        NSLog(@"ursfsfsf%@", urlStr);
        NSURL *url = [NSURL URLWithString:urlStr];
        [self.imageV sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"default.jpg"]];
        [self.myScrollerV addSubview:self.imageV];
        [self.myScrollerV addSubview:self.methodLable];
        
        
    }];
    // Do any additional setup after loading the view.
}
//自适应高度
+ (CGFloat)heightForContentText:(NSString *)text
{
    CGSize size = CGSizeMake(375 - 60, 999);
    NSDictionary *dic = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:14] forKey:NSFontAttributeName];
    CGRect frame = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    
    return frame.size.height + 150;
    
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */


@end
